<extend name="Public/base"/>

<block name="body">
    <div class="main-title">
        <h2>{$_title}</h2>
    </div>
    <notempty name="app" >
    	<form action="{:U('App/editApp')}" method="post" class="form-horizontal">
    	<input type="hidden" name="id" value="{$app.id}" />
    <else />
	    <form action="{:U('App/addApp')}" method="post" class="form-horizontal">
    </notempty>
    	<div class="form-item">
            <label class="item-label">APP名称<span class="check-tips">（APP名称格式：name-date）</span></label>
            <div class="controls">
                <input type="text" class="text input-large" name="app_name" value="{$app.app_name|default=''}">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">API版本<span class="check-tips">（API版本号格式：v1.v2，v1为大版本号，v2为小版本号）</span></label>
            <div class="controls">
                <input type="text" class="text input-large" name="api_version" value="{$app.api_version|default=''}">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">APP版本<span class="check-tips">（APP版本号格式：v1.v2，v1为大版本号，v2为小版本号）</span></label>
            <div class="controls">
                <input type="text" class="text input-large" name="app_version" value="{$app.app_version|default=''}">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">APP平台<span class="check-tips"></span></label>
            <div class="controls">
                <select name="platform" class="input-large" id="platform">
                	<foreach name="Think.config.APP_PLATFORM" key="key" item="val">
                		<if condition="$key eq $app['platform']">
    						<option value="{$key}" selected>{$val}</option>
    					<else />            			
	                		<option value="{$key}">{$val}</option>
                		</if>
                	</foreach>
                </select>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">APP文件<span class="check-tips" id="app_upload"></span></label>
            <div class="controls" id="app_file"></div>
        </div>
        <div class="form-item">
            <label class="item-label">更新类型<span class="check-tips"></span></label>
            <div class="controls">
                <select name="update_type" class="input-large">
                	<foreach name="Think.config.APP_UPDATE_TYPE" key="key" item="val">
                		<if condition="$key eq $app['update_type']">
    						<option value="{$key}" selected>{$val}</option>
    					<else />            			
	                		<option value="{$key}">{$val}</option>
                		</if>
                	</foreach>
                </select>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">更新状态<span class="check-tips"></span></label>
            <div class="controls">
                <select name="update_status" class="input-large">
                	<foreach name="Think.config.APP_UPDATE_STATUS" key="key" item="val">
                		<if condition="$key eq $app['update_status']">
    						<option value="{$key}" selected>{$val}</option>
    					<else />            			
	                		<option value="{$key}">{$val}</option>
                		</if>
                	</foreach>
                </select>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">更新说明<span class="check-tips"></span></label>
            <div class="controls">
                <textarea class="div-desc" name="description">{$app.description|default=''}</textarea>
            </div>
        </div>
        <div class="form-item">
            <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">确 定</button>
            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
        </div>
    </form>
</block>

<block name="script">
<script type="text/javascript">
	$(function(){
		var file = "{$app.file_id|default=''}";
		$("#platform").change(function(){
			//获取平台类型
			var val = $(this).val();
			$("#app_upload").empty().append('<a href="'+Think.U("File/addFile", {"file_type":val})+'">上传APP</a>');
			
			//请求APP文件信息
			ajaxRequest("{:U('App/fileInfo')}", {"platform":val}, {"func":function(data){
				if(data && data.error == 0) {
					var info = '';
					$.each(data.info, function(key, val){
						//构造APP文件信息
						info += '<span class="file_list" style="cursor:pointer">';
						info += '<input type="radio" style="vertical-align:middle" value="'+val.id+'" name="file_id" ';
						if(file == val.id) {
							info += 'checked';
						}
						info += ' /> ' + val.name + '.' + val.ext + '</span>';
						info += '<br/>';
					});
					
					info = '<div style="overflow-y:auto" class="div-desc">' + info + '</div>';
					$("#app_file").empty().append(info);

					//点击事件
					$(".file_list").click(function(){
						$(this).children('input').prop('checked', true);
					});
				} else {
					$("#app_file").empty().append( '没有APP文件');
				}
			}});
		});
		
		$("#platform").change();
	});	
    //导航高亮
    highlight_subnav('{:U('App/appList')}');
</script>
</block>
